<%@ page import="Domain.UserClient.ButtonsFunctions"%>
<%@page import="Domain.DataManager"%>
<%@ page import="java.util.*"%>
<%@ page import="objects.*"%>

<%! 
	private static HashMap<String, ButtonsFunctions> _bfs = new HashMap<String, ButtonsFunctions>();
	private static HashMap<String, HttpSession> _sessions = new HashMap<String, HttpSession>();

	void replaceBf(String name, ButtonsFunctions newBf)
	{
		ButtonsFunctions curr = _bfs.get(name);
		if(curr != null)
		{
			curr.processDisconnect();
		}
		_bfs.put(name, newBf);
	}

%>

<%
	if (session.getAttribute("dm") == null)
		response.sendRedirect("Welcome.jsp");
	else {

		DataManager dm = (DataManager) (session.getAttribute("dm"));
		ButtonsFunctions bf = (ButtonsFunctions) (session
				.getAttribute("bf"));

		if (dm.getUserStatus() == DataManager.CONNECTED) {
			response.sendRedirect("ChooseForum.jsp");
		} else {
			String userName = request.getParameter("username");
			String password = request.getParameter("password");

			replaceBf(userName, bf);

			bf.processConnect(userName, password);

			if (!dm.getConnected()) {
				response.sendRedirect("LoginFailed.jsp");
			} else {
				response.sendRedirect("ChooseForum.jsp");
			}
		}
	}
%>
